package com.ycode.bang.anbang.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ycode.bang.anbang.MyApp;
import com.ycode.bang.anbang.R;
import com.ycode.bang.anbang.activity.AdviceActivity;
import com.ycode.bang.anbang.activity.SelectPeopleActivity;


/**
 * 带x号的dialog
 */
public class DialogWithDelete {

    private static AlertDialog dialog;

    private Context mContext;


    public static void showSimpleDialog(final Context mContext,final int id,final int tag) {
        dismiss();
        dialog = null;
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_delete2, null);
        TextView message = (TextView) view.findViewById(R.id.Dialog_message);
        ImageView delete = (ImageView) view.findViewById(R.id.delete);
        final TextView message1 = (TextView) view.findViewById(R.id.Dialog_message1);
        TextView message3 = (TextView) view.findViewById(R.id.Dialog_message3);
        if (!MyApp.instance.isManage()) {
            message.setText("创建成功");
            message1.setVisibility(View.GONE);
            message3.setVisibility(View.GONE);
        }
        if(tag==4){
            message1.setText("处理工单");
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext, android.R.style.Theme_Holo_Light_Dialog);
        dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);

        dialog.getWindow().setBackgroundDrawableResource(R.drawable.transparent_bg);
        dialog.setCancelable(true);//返回键

        dialog.show();

        dialog.setContentView(view);

//        message.setText(massage);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                ((Activity) v.getContext()).finish();
            }
        });
        message1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (message1.getText().toString().trim().equals("分配工单")){
                    Intent intent = new Intent(mContext, SelectPeopleActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putInt("orderId",id);
                    bundle.putInt("tag",tag);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                    dialog.dismiss();
                    ((Activity) v.getContext()).finish();
                }else {
                    Intent intent = new Intent(mContext, AdviceActivity.class);
                    mContext.startActivity(intent);
                    dialog.dismiss();
                    ((Activity) v.getContext()).finish();
                }
            }
        });
    }

    public static void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
    }
}
